package com.myecl.poker.util;

import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

import com.myecl.poker.rules.Card;
import com.myecl.poker.state.Player;


public class Shuffle {
	private Shuffle() {
	}
	
	public static List<Card> deal(List<Card> cards, int number) {
		assert cards.size() >= number;
		List<Card> dealtCards = new LinkedList<Card>();
		for (int i = 0; i < number; i++) {
			dealtCards.add(cards.remove(random(cards.size())));
		}
		return dealtCards;
	}
	
	public static void rotate(Queue<Player> players, int times) {
		assert times >= 0;
		while(times != 0) {
			players.add(players.poll());
			times--;
		}
	}
	
	
	 public static void rotateTo(Queue<Player> players, Player button, int afterButton) {
			while(players.peek() != button) {
				players.add(players.poll());
			}
			while(afterButton != 0) {
				players.add(players.poll());
				afterButton--;
			}
	 }
	 
	private static int random(int high) {
		return (int) (Math.random() * high);
	}
	

}
